package com.lsl.singleton_pattern.triple;

/**
 * Triple类最多只能生成3个Triple类的实例，实例编号分别为0，1，2
 * 可以通过getInstance(int id)来获取该编号对应的实例
 *
 * @author Zed
 * @description
 * @date 2022/11/3 22:31
 */
public class Triple {
    private static Triple[] triples = new Triple[]{
            new Triple(0),
            new Triple(1),
            new Triple(2)
    };
    private int id;

    private Triple(int id) {
        System.out.println("the instance " + id + "is created");
        this.id = id;
    }

    public static Triple getInstance(int id) {
        return triples[id];
    }

    @Override
    public String toString() {
        return "[Tripe id=" + id + "]";
    }
}
